
function getParam(){
	var c1,c2;
	c1 = window.location.href.split("?")[1];
	alert(c1);
	c2 = c1.split("=")[1];
	getData(c1);
}
getParam();


//填充表单
function getData(param){
	var mess_url = '/citrusmonitor/question.do?method=showQAByQid&'+param;//后台填充

$.ajax({
	type:'GET',
	url:mess_url,

	dataType:'JSON',
	success:function(data){
		console.log(data);
		var title = document.getElementById("title");
		var ques_content = document.getElementById("ques_content");
		var image_box = document.getElementsByClassName("image_box")[0];
		var questionId = document.getElementById("questionId");
		title.value = data.question["summary"];
		ques_content.value = data.question["content"];
		questionId.value = data.question["questionId"];
		if(data.question["filePath"]){
			image_box.innerHTML = '<img src="'+data.question["filePath"]+'">';
		}
		resizeBox();
	},
	error:function(){
		alert("问题加载失败");
	}
});


}


//提交表单
var submit = document.getElementsByClassName("submit")[0];
submit.onclick = function(){
	//判断是否为专家
	$.ajax({
			url : '/citrusmonitor/answer.do?method=loadStatus',//后台填充URL
			dataType : 'json',
			cache : false,
			success : function(data) {
			if (data == 1) {//1表示已登录
 			postData();
			}else{
            alert("您还未登录！！！");
            //跳转到登陆的页面
            window.location.href = "";//登录的链接
			 }
			}
		});

}

function postData(){
	var ans_content = document.getElementById("ans_content");
	var questionId = document.getElementById("questionId");
	if(ans_content.value==''){
		alert("信息不能为空！！");
	}else{
		$.ajax({
			type:'POST',
			url:'/citrusmonitor/answer.do?method=addA',//后台填充页面
			dataType:'json',
			data:{
				content:ans_content.value,
				questionId:questionId.value
			},
			success:function(res){
				if(res.status){
					alert("提交成功！");
					window.location.href = "/citrusmonitor/question_ul_exp.html";
				}else{
					alert("提交失败！");
				}
			},
			error:function(){
				alert("提交失败！!");
			}
		});
	}
}








//调整问题框的大小
var image_box = document.getElementsByClassName("image_box")[0];
var ques_content = document.getElementById("ques_content");
var content_box = document.getElementsByClassName("content_box")[0];
function resizeBox(){	
	if(!image_box.getElementsByTagName("img")[0]){
		image_box.style.height = "0px";
		ques_content.style.height = "100%";
	}
}

